package com.kbcss.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ReportInsert
 */
public class ReportInsert extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReportInsert() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		RequestDispatcher rd;
		int xx=0;
		HttpSession ss=request.getSession();
		ss.getAttribute("id");
		String sid=request.getParameter("sid");
		int cca=Integer.parseInt(request.getParameter("cca"));
		int disc=Integer.parseInt(request.getParameter("disc"));
		int academic=Integer.parseInt(request.getParameter("academic"));
		try{
		     Class.forName("com.mysql.jdbc.Driver");
		     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/kbcssdb", "root", "mysql");
		     PreparedStatement ps=con.prepareStatement("insert into asmtreport(userid,acdperf,ccaperf,disparticipate) values(?,?,?,?)");
		     ps.setString(1,sid);
		     ps.setInt(2,academic);
		     ps.setInt(3,cca);
		     ps.setInt(4,disc);
		     xx=ps.executeUpdate();
	            if(xx==1){
	                         //con.commit();
	                         out.println(xx);
	                         rd=request.getRequestDispatcher("fprofile.jsp");
	             			 rd.forward(request,response);
	                     }
	}
	catch(Exception ex){
		out.println("error...."+ex.getMessage());
	}
	}

}
